package com.redislock.aop.tool.exception;

import com.redislock.aop.tool.domain.AjaxResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Log4j2
public class GlobalExceptionHandler {
    /**
     * 业务异常
     * @param businessException
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public AjaxResult BusinessException(BusinessException businessException){
        log.error(businessException.getMessage());
        return AjaxResult.error(businessException.getMessage());
    }

    /**
     * 系统异常
     * @param systemException
     * @return
     */
    @ExceptionHandler(SystemException.class)
    public AjaxResult SystemException(SystemException systemException){
        log.error(systemException.getMessage());
        return AjaxResult.error("请找管理员解决，谢谢");
    }
}
